<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>保证金退回</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
</style>
</head>
<body class="iframeBody">
<div class="Wrapper">
     <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="caption">
			<span class="title">基础信息 </span>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">项目名称</div>
		   <div class="field">
              <span id="fncPrjNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">项目编号</div>
		   <div class="field">
              <span id="fncPrjIdShow" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">融资机构</div>
		   <div class="field">
              <span id="fncInsNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">已付保证金</div>
		   <div class="field">
              <span id="mrgnAtm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">付款时间</div>
		   <div class="field">
             <span id="payTm"></span> 
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">剩余保证金</div>
		   <div class="field">
		     <span id="srplsMrgnShow"></span>
           </div>
		</div>
	</div><br/>
	<div class="fieldset1 tabel_col_s clearFix" > <!-- fieldset1 tabel_col tabel_col_s clearFix -->
	   <div class="caption">
		   <span class="title" >抵扣记录 </span>
	   </div>
	  <div id="mrgnDeductedligergrid" class="sq-grid"></div>
	</div><br/>
	<div class="fieldset1 tabel_col_s clearFix" > <!-- fieldset1 tabel_col tabel_col_s clearFix -->
	   <div class="caption">
		   <span class="title" >可分解还款列表 </span>
	   </div>
	  <div id="mrgnDeductingligergrid" class="sq-grid"></div>
	   <div class="fieldBox col_100"  align="right">
		   <div class="label">合计</div>
		   <div class="field">
             <input name="totalAtm" id="totalAtm" type="text" class="ui-textbox" value="" disabled="disabled" >
           </div>
	   </div>
	</div>
	<!-- hidden -->
	<input name="lgcId" id="lgcId" type="hidden" class="ui-textbox" value="${lgcId}"  >
	<input name="prjLgcSn" id="prjLgcSn" type="hidden" class="ui-textbox" value="${prjLgcSn}"  >
</div>

<script type="text/javascript">
   $(function() {
	  initData();
	 });
   
   function initData(){
	  var lgcId=$("#lgcId").val();
	  var prjLgcSn=$("#prjLgcSn").val();
	  if(!lgcId)  return;
	  var data=new Object();
	  data["lgcId"]=lgcId;
	  data["prjLgcSn"]=prjLgcSn;
	  var _url = '<%=path%>/rfbase/mrgnmanageinfo/getMrgnDeductInfoById.do';
	   AjaxUtils.ajaxPost(_url, data, callback);
	}
		
	  //新增回调
   function callback(msg){
	  if(msg.success == 1){
		  setData(msg.data);//设置数据
	  }else{
		  UIUtils.alertError(msg.info);
	  }
   }
		
		//设置页面数据
   function setData(data){
	    var mrgnDeductedInfoList=data["mrgnDeductInfo"];
        var mrgnPayingInfo=data["mrgnPayingInfo"];
	    var mrgnTkOffInfoList=mrgnPayingInfo.mrgnTkOffInfoList;
	    $("#fncInsNm").html(mrgnPayingInfo.fncInsNm);
	    $("#srplsMrgnShow").html(moneyChange(mrgnPayingInfo.srplsMrgn));
		$("#fncPrjNm").html(mrgnPayingInfo.fncPrjNm);
		$("#fncPrjIdShow").html(mrgnPayingInfo.fncPrjId);
		$("#mrgnAtm").html(moneyChange(mrgnPayingInfo.mrgnAtm));
		$("#payTm").html(renderDateChange(mrgnPayingInfo.payTm));
		$("#fncPrjId").val(mrgnPayingInfo.fncPrjId);
		$("#prjLgcSn").val(mrgnPayingInfo.id);
		var totalAtm=0;
		for(var i=0;i<mrgnTkOffInfoList.length;i++){
			totalAtm+=mrgnTkOffInfoList[i].thsRepyAmt;
		}
		$("#totalAtm").val(totalAtm);
		f_showMrgnDeductedInfo(mrgnDeductedInfoList);
		f_showMrgnDeductingInfo(mrgnTkOffInfoList);
  };

  function f_getDetailData(listChange)
  {
      var data = { Rows: [] };
      for (var i = 0; i < listChange.length; i++)
      {
         data.Rows.push(listChange[i]);
      }
      return data;
  }
  //显示坐扣记录
  function f_showMrgnDeductedInfo(mrgnTkOffInfoList)
  { 
    $("#mrgnDeductedligergrid").ligerGrid({
        columns: [
            { display: '申请抵扣金额',name: "thsRepyAmt", width: 150, render: function (rowdata, rowindex, value, column) { 
            	var money =moneyChange(value);
                return money;
        		},
    	      enabledSort:true},       
            { display: '项目编号', name: 'payPrjId', width: 150},
            { display: '期次', name: 'payPd', width: 150 },
            { display: '抵扣项目', name: 'feeClsNm', width: 100,
            	render: function (rowdata, rowindex, value){
            		if(rowdata.feeClsCd==1)
            		 return "本金";
            		else{
            		 return "利息";	
            		}
            	}},
            { display: '抵扣状态', name: '', width: 100,
            	render: function (rowdata, rowindex, value){
           		 return "审核通过";
           	}}
        ],
        usePager:false,
        data:f_getDetailData(mrgnTkOffInfoList),
        width:'100%',
        height:'auto',
        heightDiff:-2,
        checkbox:false,
        rownumbers:true,
    });
  }
  
   //显示还款List
    function f_showMrgnDeductingInfo(mrgnTkOffInfoList)
    { 
	    $("#mrgnDeductingligergrid").ligerGrid({
	        columns: [
	            { display: '支付表逻辑编号',name: "payLgcSn", width: 150,hide: true},  
	            { display: '项目编号', name: 'payPrjId', width: 150},
	            { display: '期次', name: 'payPd', width: 150 },
	            { display: '应还项目', name: 'feeClsNm', width: 100,
	            	render: function (rowdata, rowindex, value){
	            		if(rowdata.feeClsCd==1)
	            		 return "本金";
	            		else{
	            		 return "利息";	
	            		}
	            	}},
	            { display: '应还日期', name: 'payDt', width: 100, render:renderDate,},
	            { display: '应还金额', name: 'feeAmt', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true},      
	            { display: '已还金额', name: 'paidUpAmt', width: 200, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true},      
	            { display: '剩余金额', name: 'arAmt', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true},      
	            { display: '本次还款', name: 'thsRepyAmt', width: 200, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}     
	        ],
	        usePager:false,
	        data:f_getDetailData(mrgnTkOffInfoList),
	        width:'100%',
	        height:'auto',
	   /*      groupColumnName:'payPrjId',
	        groupColumnDisplay:'项目编号', */
	        checkbox:false,
	        rownumbers:true
	    });
    }
	
 //格式化时间
 function renderDateChange(value){
	var dateStr = "";
	if(null != value &&  ""!= value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
	}
	return dateStr;
 } 
 
//格式化时间
 function renderDate(rowdata, index, value){
	var dateStr = "";
	if(null != value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
	}
	return dateStr;
 }
 function update(){
	 var lgcId=$("#lgcId").val();
	 Add_navTab('PrdSpl_9','修改','<%=path%>/rfbase/mrgnmanageinfo/toDeductOprtUpdatePage.do?lgcId='+lgcId);
 }
 
//格式化金额
 function moneyChange(value) { 
		var h = '';
			if(value&&value!="null"){
		    h+=fmoney(value, 2);
			}else{
			h+="0.00";
			}
         return h;
		}
 
 //格式化金额
 function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
 
 
</script>

</body>
</html>
